package com.nn.smart.bus.commons.tools.utils;

import java.util.Random;

public class RandomUtil {
    /**
     * 根据需要生成指定长度的纯数字随机数,这个随机数的每一位都是从(0-9)这个产生的一位
     *
     * @param codeLen
     * @return
     */
    public static String getNewRandomCode(int codeLen) {
        Random randomCode = new Random();
        String strCode = "";
        while (codeLen > 0) {
            int charCode = randomCode.nextInt(9);
            strCode += charCode;
            codeLen--;
        }
        return strCode;
    }

    public static int getRandomNum(int min, int max) {
        Random random = new Random();
        return random.nextInt(max - min + 1) + min;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10000; i++) {
            int s = RandomUtil.getRandomNum(1, 10);
            if (s < 1 || s > 10) {
                System.out.println(s);
            }
        }
    }
}
